define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'business.district/index',
        add_url: 'business.district/add',
        edit_url: 'business.district/edit',
        delete_url: 'business.district/delete',
        export_url: 'business.district/export',
        modify_url: 'business.district/modify',
        manage_url: 'business.district_admin/index',
        shop_url: 'business.shop/index',
        shop_category_url: 'district.shop_category/index',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'add', 'delete'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id'},
                    {field: 'name', title: '名称'},
                    {field: 'type', title: '类型',selectList:{0:'商圈',1:'连锁'}},
                    {field: 'create_time', title: '创建时间', search: 'range'},
                    {
                        width: 300, title: '操作', templet: ea.table.tool,
                        operat: [
                            'edit',
                            [{
                                text: '管理员',
                                url: init.manage_url,
                                method: 'open',
                                fieldExtra: {'district_id': 'id'},
                                auth: '',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                extend: 'data-full="true"',
                            }],
                            [{
                                text: '店铺',
                                url: init.shop_url,
                                method: 'open',
                                fieldExtra: {'district_id': 'id'},
                                auth: 'shop',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                extend: 'data-full="true"',
                            }],
                            [{
                                text: '店铺类别',
                                url: init.shop_category_url,
                                method: 'open',
                                fieldExtra: {'district_id': 'id'},
                                auth: 'shop',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                extend: 'data-full="true"',
                            }],
                            'delete']
                    },
                ]],
                done: function () {
                    $(".layui-table-body>table>tbody>tr").each(function (index, val) {
                        $($(".layui-table-fixed .layui-table-body table tr")[index]).height($(val).height());
                    });
                },
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});